<!--时间过滤-->
<template>
  <article class="filter-date-panel" v-show="isShow" @click="hide()">
    <section class="inner" @click.stop="">
      <div class="panel-date">
        <div class="panel-btn" @click="showTimePicker('startTime')">{{startTime||'开始时间'}}</div>
        <div class="panel-line">-</div>
        <div class="panel-btn" @click="showTimePicker('endTime')">{{endTime || '结束时间'}}</div>
      </div>

    </section>
  </article>
</template>

<script>
  import moment from 'moment'
  import tools from '@/utils/tools'
  export default {
    name: '',
    props: ['value'],
    data () {
      return {
        isShow: this.value,
        startTime: '',
        endTime: ''
      }
    },
    methods: {
      showTimePicker (flag) {
        this.$createDatePicker({
          min: new Date(2008, 7, 8),
          max: new Date(),
          value: new Date(),
          onSelect: (selectedTime, selectedText, formatedTime) => {
            this[flag] = moment(selectedTime).format('YYYY-MM-DD')
          }
        }).show()
      },
      hide () {
        this.isShow = false
        this.$emit('input', this.isShow)
      },
      onFilter () {
        this.$emit('onFilter', {startTime: this.startTime, endTime: this.endTime})
      }
    },
    watch: {
      value (value) {
        this.isShow = value
      }
    }
  }
</script>

<style scoped lang="scss">
.filter-date-panel {
  background:rgba(#000,.5);
  position:fixed;
  z-index: 11;
  top:0;left:0;
  width:100%;height:100%;
  .inner {
    background:#fff;
    position: absolute;
    left:0;
    bottom:0;
    width:100%;
    height:350px;
    padding:20px 0;
  }
  .panel-date {
    margin:0 20px;
    display:flex;
    .panel-btn {
      white-space: nowrap;
      box-sizing:border-box;
      line-height:36px;
      background:#fafafa;
      border:1px solid #eee;
      text-align:center;
      overflow:hidden;
      padding:0 5px;
      color:#666;
      flex:1;
      font-size:px2rem(26);
    }
    .panel-line {
      line-height:36px;
      padding:0 10px;
    }
  }
}
</style>
